#ifndef NETWORK_RESPONSE_H
#define NETWORK_RESPONSE_H

#include <QObject>
#include <QVariant>


class QNetworkReply;
namespace Network {

class Response : public QObject
{
    Q_OBJECT
public:
    explicit Response(QObject *parent = 0);

    enum Type {
        Login,
        Friend,
        ProfileType,
        GetProfileType,
        UpdateProfile,
        GetStatus,
        GetMessageStatusType,
        PostMessageStatusType,
        GetFriendsStatus,
        UpdateStatus,
        GetProfileFriend,
        GetHistoryType,
        GetImage,
        AddFriendRequest,
        OpeningUpdateApp,
        UpdateArticleContent,
        UpdateListArticles,
        UpdateMoreListArticles,
        UpdateNewListArticles
    };

    enum Error {
        None,
        Network,
        Syntax,
        Property
    };

    virtual Type type() const = 0;

    virtual void parse(QNetworkReply &reply);

public:
    inline Error error() const {
        return m_error;
    }

    inline int errorResponsed() const {
        return m_errorResponsed;
    }

    inline const QString &message() const {
        return m_message;
    }

protected:
    void setError(const Error &error, const QString &message, const int errorResponse = 0);

private:
    virtual void parse(const QByteArray &data) = 0;

private:
    Error m_error;
    int m_errorResponsed;  // error code from Server
    QString m_message;
};

}
#endif // NETWORK_RESPONSE_H
